/*

Problem 17
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?


NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
*/

var Enumerable = require('linq');
var start = new Date().getTime();
var BigNumber = require('./BigNumber'); // Example for including files
var Big = require('big.js');

function writeNumber(n) {

    var numberStr = "";

    var hundreds = Math.floor(n / 100);

    switch (hundreds) {
    case 1:
        {
            numberStr = "one hundred ";
        }
        break;
    case 2:
        {
            numberStr = "two hundred ";
        }
        break;
    case 3:
        {
            numberStr = "three hundred ";
        }
        break;
    case 4:
        {
            numberStr = "four hundred ";
        }
        break;
    case 5:
        {
            numberStr = "five hundred ";
        }
        break;
    case 6:
        {
            numberStr = "six hundred ";
        }
        break;
    case 7:
        {
            numberStr = "seven hundred ";
        }
        break;
    case 8:
        {
            numberStr = "eight hundred ";
        }
        break;
    case 9:
        {
            numberStr = "nine hundred ";
        }
        break;
    case 10:
        {
            numberStr = "one thousand";
        }
        break;
    }

    if (n % 100 > 0) {

        if(n > 100)
        numberStr += 'and ';

        var t = n % 100;

        if (t < 20) {
            switch (t) {
            case 1:
                {
                    numberStr += "one";
                }
                break;
            case 2:
                {
                    numberStr += "two";
                }
                break;
            case 3:
                {
                    numberStr += "three";
                }
                break;
            case 4:
                {
                    numberStr += "four";
                }
                break;
            case 5:
                {
                    numberStr += "five";
                }
                break;
            case 6:
                {
                    numberStr += "six";
                }
                break;
            case 7:
                {
                    numberStr += "seven";
                }
                break;
            case 8:
                {
                    numberStr += "eight";
                }
                break;
            case 9:
                {
                    numberStr += "nine";
                }
                break;
            case 10:
                {
                    numberStr += "ten";
                }
                break;
            case 11:
                {
                    numberStr += "eleven";
                }
                break;
            case 12:
                {
                    numberStr += "twelve";
                }
                break;
            case 13:
                {
                    numberStr += "thirteen";
                }
                break;
            case 14:
                {
                    numberStr += "fourteen";
                }
                break;
            case 15:
                {
                    numberStr += "fifteen";
                }
                break;
            case 16:
                {
                    numberStr += "sixteen";
                }
                break;
            case 17:
                {
                    numberStr += "seventeen";
                }
                break;
            case 18:
                {
                    numberStr += "eighteen";
                }
                break;
            case 19:
                {
                    numberStr += "nineteen";
                }
                break;
            }
        } else {
            var d = Math.floor(t / 10);
            var s = t % 10;

            switch (d) {
            case 2:
                {
                    numberStr += "twenty ";
                }
                break;
            case 3:
                {
                    numberStr += "thirty ";
                }
                break;
            case 4:
                {
                    numberStr += "forty ";
                }
                break;
            case 5:
                {
                    numberStr += "fifty ";
                }
                break;
            case 6:
                {
                    numberStr += "sixty ";
                }
                break;
            case 7:
                {
                    numberStr += "seventy ";
                }
                break;
            case 8:
                {
                    numberStr += "eighty ";
                }
                break;
            case 9:
                {
                    numberStr += "ninety ";
                }
                break;
            }
    
        switch (s) {
            case 1:
                {
                    numberStr += "one";
                }
                break;
            case 2:
                {
                    numberStr += "two";
                }
                break;
            case 3:
                {
                    numberStr += "three";
                }
                break;
            case 4:
                {
                    numberStr += "four";
                }
                break;
            case 5:
                {
                    numberStr += "five";
                }
                break;
            case 6:
                {
                    numberStr += "six";
                }
                break;
            case 7:
                {
                    numberStr += "seven";
                }
                break;
            case 8:
                {
                    numberStr += "eight";
                }
                break;
            case 9:
                {
                    numberStr += "nine";
                }
                break;}
        }
    }

    return numberStr;
}

var solveTask = function (n) {

    return writeNumber(n);
};

var result = 0;

for(var i = 0; i <= 1000; i++) {
    var str = solveTask(i);
    console.log(str, str.replace(/ /g,''), str.replace(/ /g,'').length);
    result += str.replace(/ /g,'').length;
}

console.log("Result: ", result);

var end = new Date().getTime();
var time = end - start;

console.log("Time: ", time);

require('readline')
    .createInterface(process.stdin, process.stdout)
    .question("Press [Enter] to exit...", function(){
        process.exit();
});